//
//  MineActiveTableViewController.m
//  MJApp
//
//  Created by wangliang on 15/3/30.
//  Copyright (c) 2015年 wangliang. All rights reserved.
//

#import "MineActiveTableViewController.h"

#import "MineActiveTableViewCell.h"
#import "ActivityDetailVc.h"

@interface MineActiveTableViewController ()<HomeCellDelegate>

@property(nonatomic,strong)NSMutableArray *tableList;

@end

@implementation MineActiveTableViewController

- (NSMutableArray *)tableList {
    
    if (!_tableList) {
        
        _tableList = [NSMutableArray array];
    }
    return _tableList;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self UI];
    [self obationData];
}

- (void)UI {
    
    self.title = @"活动";
    self.tableView.separatorColor = [UIColor clearColor];
    self.tableView.backgroundColor = Color_Back_Black;
}

- (void)obationData {
    
    NSDictionary *dic = @{@"page":@"1"};
    [WLHttpRequestAfter activityGetActivityWithParam:dic usingSucessBlock:^(BOOL isSucess, NSDictionary *resultDictionary) {
        
        [self.tableList addObjectsFromArray:resultDictionary[@"data"][@"new"]];
        [self.tableList addObjectsFromArray:resultDictionary[@"data"][@"past"]];
        [self.tableView reloadData];
        
    } andFailureBlock:^(NSError *resultError) {
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.tableList.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    MineActiveTableViewCell *cell = (MineActiveTableViewCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
    return cell.cellHigh;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    MineActiveTableViewCell *cell = [MineActiveTableViewCell initWithTableView:tableView];
    cell.infoDic = self.tableList[indexPath.row];
    cell.delegate = self;
    return cell;
}

- (void)homeCell:(id)cell withInfo:(id)info {
    
    NSDictionary *dic = (NSDictionary *)info;
    ActivityDetailVc *activityDetailVc = [[ActivityDetailVc alloc] initWithDic:dic];
    [self.navigationController pushViewController:activityDetailVc animated:YES];
}

@end
